export function compareArrays<T>(arr1: T[], arr2: T[]) {
  const added = arr2.filter((item) => !arr1.includes(item));
  const removed = arr1.filter((item) => !arr2.includes(item));

  return { added, removed };
}

export function toObj(arr: any[], key = 'key', value?: string | ((item: any) => any)) {
  return arr.reduce((pre, obj) => {
    if (!value) pre[obj[key]] = obj;
    else pre[obj[key]] = typeof value === 'function' ? value(obj) : obj[value];
    return pre;
  }, {});
}

export function fromObj(obj: any, key = 'key', value = 'value') {
  return Object.keys(obj).map((k) => ({ [key]: k, [value]: obj[k] }));
}
